package picol.model;

import java.util.ArrayList;
import java.util.List;
import picol.model.asa.inst.ASAInstPicoL;
import picol.model.exception.FileNameException;
import picol.model.jjgener.ExprArbre;
import picol.model.jjgener.ParseException;

/**
 * Classe du model
 * @author Aurélien Marcel - Julien Sanderson
 */
public class ModelImp implements Model {

    private List<Integer> listDebug;
    private Boolean debugMode;
    private ASAInstPicoL inst;

    /**
     * Default Constructor
     */
    public ModelImp() {
        this.listDebug = new ArrayList<Integer>();
        this.debugMode = false;
    }

    public void parse(String _fileName) throws FileNameException, ParseException {
        if (this.debugMode == false) {
            ASAInstPicoL.resetTableSymbole();
            ExprArbre a = new ExprArbre(_fileName);
            this.inst = (ASAInstPicoL) a.launchParser();
            //initialisation du nombre d'instructions
            this.inst.setListSize(this.inst.getNbInst());
        }
    }

    public boolean launch() {

        if (!debugMode) {
            inst.executer();
            return true;
        } else {
            return inst.executerDebug();
        }
    }

    public void setDebugMode(boolean _debug) {
        this.debugMode = _debug;
    }

    public void setDebugLine(int _line) {
        if (this.listDebug.contains(_line)) {
            boolean remove = this.listDebug.remove((Integer) _line);
        } else {
            this.listDebug.add(_line);
        }
    }

    public int getDebugLine() {
        return this.inst.getInstIncr();
    }

    public String getVarList() {
        return this.inst.getVarList();
    }
}
